package com.zry.pda.retrofit

import android.util.Log

import com.tsy.sdk.myokhttp.MyOkHttp
import com.zry.pda.config.MyApplication

import java.util.concurrent.TimeUnit

import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory
import retrofit2.converter.gson.GsonConverterFactory

/**
 * @创建者 ray@wdzj.com
 * @描述 配置Retrofit（配置网络缓存cache、配置持久cookie免登录）
 */

class BaseApiRetrofit {

    companion object {

        //    public static String BASE_URL = "http://cs.sxjagf.com/";

        val BASE_URL = "http://fx.17sys.cn/service/"


        val APK_NAME = "追溯2.0"

        val DownLoadApp = "$BASE_URL/DownLoadApp?VersionType=PDA"
    }


    private val httpLoggingInterceptor = HttpLoggingInterceptor(HttpLoggingInterceptor.Logger { message -> Log.e("RetrofitLog", "retrofitBack=$message") }).setLevel(HttpLoggingInterceptor.Level.BODY)


    val okHttpClient = OkHttpClient.Builder().cookieJar(MyApplication.instance().cookieJar)
            .addInterceptor(httpLoggingInterceptor)
            .connectTimeout(15, TimeUnit.SECONDS)
            .readTimeout(20, TimeUnit.SECONDS)
            .writeTimeout(20, TimeUnit.SECONDS)
            .retryOnConnectionFailure(true).build()!!

    val myOkHttp = MyOkHttp(okHttpClient)


    val retrofit = Retrofit.Builder()
            // 设置 网络请求 Url
            .baseUrl(BASE_URL)
            //设置使用Gson解析(记得加入依赖)
            .addConverterFactory(NullOnEmptyConverterFactory())
            .addConverterFactory(GsonConverterFactory.create())
            .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
            .client(okHttpClient)
            .build().create(ApiDynamic::class.java)!!


}
